/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treeship.core.service.impl;

import treeship.core.exceptions.CantDoThatException;

/**
 *
 * @author Moonchild
 */
public class LoggerImpl {

    private StringBuffer stringBuffer = new StringBuffer();
    private static int MAX_LOG_SIZE = 500;

    public LoggerImpl() {
    }

    public String getLog() {
        return stringBuffer.toString();
    }

    public void addLog(String s) {
        stringBuffer.append(s + "\n");
        if (stringBuffer.length() > MAX_LOG_SIZE) {
            stringBuffer = new StringBuffer(stringBuffer.substring(stringBuffer.length() - MAX_LOG_SIZE, stringBuffer.length()));
//            stringBuffer = stringBuffer.delete(0, stringBuffer.capacity() - MAX_LOG_SIZE);            
        }
    }

    public void handleException(CantDoThatException e) {
        addLog(e.getMessage());
    }
}
